package com.xjtu.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.xjtu.dto.UserPageDto;
import com.xjtu.entity.Assessment;
import com.xjtu.entity.CapabilityAssessment;
import com.xjtu.exception.BaseException;
import com.xjtu.mapper.*;
import com.xjtu.result.PageResult;
import com.xjtu.service.BaseInfoService;
import com.xjtu.vo.UserVo;
import com.xjtu.vo.baseInfo.AssessmentReportVo;
import com.xjtu.vo.baseInfo.AssessmentTableVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@Slf4j
public class BaseInfoServiceImpl implements BaseInfoService {

    @Autowired(required = false)
    private CapabilityAssessmentMapper capabilityAssessmentMapper;

    @Autowired(required = false)
    private AssessmentMapper assessmentMapper;

    @Autowired(required = false)
    private AssessmentOptionMapper assessmentOptionMapper;

    @Autowired(required = false)
    private AssessmentDetailsMapper assessmentDetailsMapper;

    @Autowired(required = false)
    private AssessmentIndicatorMapper assessmentIndicatorMapper;

    @Override
    public AssessmentTableVo queryAssessmentTableById(Integer id) {
        CapabilityAssessment capabilityAssessment = capabilityAssessmentMapper.selectByPrimaryKey(Long.valueOf(id));
        if(capabilityAssessment == null){
            throw new BaseException("记录不存在");
        }
        AssessmentTableVo resp = new AssessmentTableVo();
        resp.setAssessment(capabilityAssessment);
        return resp;
    }

    @Override
    public List<CapabilityAssessment> queryAssessmentTableListsByElderlyId(Integer elderlyId) {
        List<CapabilityAssessment> resp = capabilityAssessmentMapper.queryByElderlyId(elderlyId);
        return resp;
    }

    @Override
    public PageResult pageQuery(Integer page, Integer size, String name) {
        PageHelper.startPage(page, size);
        Page<CapabilityAssessment> userPage = capabilityAssessmentMapper.pageQuery(name);
        long total = userPage.getTotal();
        List<CapabilityAssessment> records = userPage.getResult();
        return new PageResult(total, records);
    }

    @Override
    public PageResult pageQueryAssessmentReport(Integer page, Integer size, String name) {
        PageHelper.startPage(page, size);
        Page<AssessmentReportVo> userPage = assessmentMapper.pageQuery(name);
        long total = userPage.getTotal();
        List<AssessmentReportVo> records = userPage.getResult();
        return new PageResult(total, records);
    }


}
